import time

from selenium.webdriver.common.by import By

from common.Utils import BlogDriver
from tests.BlogLogin import BlogLogin


class BlogDetail():
    url = ""
    driver = ""
    def __init__(self):
        # 列表详情页链接
        self.url = "http://8.137.19.140:9090/blog_detail.html?blogId=114697"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    # 登录状态下进入博客详情页测试
    def loginBlogDetail(self):
        # 首先判断标题是否为“博客详情页”
        title = self.driver.title
        assert title == "博客详情页"
        # 再判断是否有详情页相关元素
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(1)")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > a")
        BlogDriver.getScreenshot()

    # 未登录状态下无法打开详情页
    def logoutBlogDetail(self):
        self.driver.get(self.url)
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container-login > div > h3")
        BlogDriver.getScreenshot()



